import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class EditCategoryDialog {
  static Future<String?> showCategoryName(BuildContext context,
      {String? categoryName}) async {
    TextEditingController controller = TextEditingController(text: categoryName == null? "":categoryName);
    return showDialog<String>(context: context, builder: (context){
      return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Dialog(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
            child: Column(
              children: [
                Container(
                  child: Text(categoryName == null? "添加分类":"编辑分类",style: TextStyle(color: Color(0xff292C30),fontSize: 17),),
                  padding: EdgeInsets.only(top: 14,bottom: 8),
                ),
                Divider(
                  height: 1,
                  color: Color(0xffdddddd),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 27,vertical: 17),
                  child: TextField(
                    controller: controller,
                    decoration: InputDecoration(
                        hintText: "请输入分类名称",
                        contentPadding: EdgeInsets.symmetric(horizontal: 7,vertical: 5),
                        border:OutlineInputBorder(
                            borderRadius: BorderRadius.circular(5),
                            borderSide:BorderSide(color: Color(0xffB5B5B5))
                        )
                    ),
                  ),
                ),
                Divider(
                  height: 1,
                  color: Color(0xffdddddd),
                ),
                SizedBox(
                  height: 40,
                  child: Row(
                    children: [
                      Expanded(
                          child:FlatButton(
                            onPressed: (){
                              Navigator.pop(context);
                            },
                            child: Text("取消",style: TextStyle(color: Color(0xff3f66f5),fontSize: 17),),
                          )
                      ),
                      VerticalDivider(
                        width: 1,
                        color: Color(0xffdddddd),
                      ),
                      Expanded(
                          child:FlatButton(
                            onPressed: (){
                              String text = controller.text.trim();
                              if (text.length == 0) {
                                EasyLoading.showToast('请输入分组名称');
                                return;
                              } else {
                                Navigator.pop(context, text);
                              }
                            },
                            child: Text("确定",style: TextStyle(color: Color(0xffff5858),fontSize: 17),),
                          )
                      ),
                    ],
                  ),
                )
              ],
            ),
          )
        ],
      );
    });
  }
}